package com.ninthgroup.service.Impl;

import com.ninthgroup.entity.Condition;
import com.ninthgroup.entity.MessageBooking;
import com.ninthgroup.mapper.ConditionMapper;
import com.ninthgroup.service.ConditionService;
import com.ninthgroup.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ConditionServiceImpl implements ConditionService {
    @Autowired
    private ConditionMapper conditionMapper;
//    查询
    @Override
    public Result selectAll() {
        List<ConditionMapper> conditionMappers = conditionMapper.selectAll();
        return new Result(200 ,"查询成功",conditionMappers);
    }
//    添加
    @Override
    public Result insertAdd(Condition condition) {
        if (condition.getcDate() ==null){
            condition.setcDate(new Date());
        }

        condition.setcStatus(1);
        conditionMapper.insertSelective(condition);

        Condition condition1 = conditionMapper.selectByCases(condition.getcCases());
        return new Result(200,"添加成功",condition1);
    }


//    删除
    @Override
    public Result del(Integer cId) {
        conditionMapper.deleteByPrimaryKey(cId);
        return new Result(200,"删除成功");
    }
// 修改
    @Override
    public Result update(Condition condition) {
        conditionMapper.updateByPrimaryKey(condition);
        System.out.println("condition22 = " + condition);
        return new Result(200,"修改成功");
    }

    @Override
    public Result updateOneAdvise(Condition condition) {

        int i = conditionMapper.updateByPrimaryKeySelective(condition);

        return new Result(200,"成功");
    }

    @Override
    public Result selectOne(Integer cId) {
        Condition condition = conditionMapper.selectByPrimaryKey(cId);
        return new Result(200,"成功",condition);
    }
}